﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_management
{
    public partial class frmDanhSachLop : Form
    {
        Connection connect = new Connection();
        string ten, diachi, sdt, logo;
        public frmDanhSachLop()
        {
            InitializeComponent();
        }

        private void frmDanhSachLop_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
            cBolop.ResetText();
            DataTable dt = connect.getDS("Select MaLop From LOP");
            int Count;
            Count = dt.Rows.Count;
            for (int i = 0; i < Count; i++)
            {
                string stringcomboBox = dt.Rows[i]["MaLop"].ToString();
                if (stringcomboBox != "N/A")
                    cBolop.Items.Add(stringcomboBox);
            }
            cBolop.SelectedIndex = 0;

            DataTable a = new DataTable();
            a = connect.getDS("Select * from ThongTin");
            ten = a.Rows[0]["Ten"].ToString();
            sdt = a.Rows[0]["DT"].ToString();
            diachi = a.Rows[0]["DiaChi"].ToString();
            logo = a.Rows[0]["Logo"].ToString();

            loaddata();
        }

        void loaddata()
        {
            reportViewer1.Reset();
            reportViewer1.LocalReport.ReportEmbeddedResource = "Student_management.DSL.rdlc";
            reportViewer1.LocalReport.DataSources.Clear();
            Microsoft.Reporting.WinForms.ReportDataSource newDataSource = new Microsoft.Reporting.WinForms.ReportDataSource("Baocaohk_BaoCao", connect.getDS("SELECT HOTEN, GioiTinh, NGAYSINH, DIACHI, MALOP, MAHS FROM HOCSINH WHERE MALOP = '" + cBolop.Text + "'"));
            newDataSource.Name = "DataSet1";
            reportViewer1.LocalReport.DataSources.Add(newDataSource);
            reportViewer1.LocalReport.EnableExternalImages = true;
            List<Microsoft.Reporting.WinForms.ReportParameter> Parameters = new List<Microsoft.Reporting.WinForms.ReportParameter>();
            Microsoft.Reporting.WinForms.ReportParameter param = new Microsoft.Reporting.WinForms.ReportParameter();
            Parameters.Add(param);
            param = new Microsoft.Reporting.WinForms.ReportParameter("Ten", ten);
            Parameters.Add(param);
            param = new Microsoft.Reporting.WinForms.ReportParameter("SDT", sdt);
            Parameters.Add(param);
            param = new Microsoft.Reporting.WinForms.ReportParameter("Diachi", diachi);
            Parameters.Add(param);
            param = new Microsoft.Reporting.WinForms.ReportParameter("Logo", logo);
            Parameters.Add(param);
            reportViewer1.LocalReport.SetParameters(Parameters);
            this.reportViewer1.RefreshReport();
        }
        private void cBolop_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddata();
        }
    }
}
